package com.study.hadoop.mapreduce.mapJoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @Author huang
 * @Date 2022/1/20 13:44
 * @Version 1.0
 */
public class Driver {
    public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException, ClassNotFoundException {
        //获取job
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        //配置信息
        job.setJarByClass(Driver.class);
        job.setMapperClass(MapJoinMapper.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        //加载缓存数据
        job.addCacheFile(new URI("file:///D:/生活/study/hadoop/资料/11_input/tablecache/pd.txt"));
        //map段join不需要reducer,设置reduceTask为0
        job.setNumReduceTasks(0);

        FileInputFormat.setInputPaths(job,new Path("D:\\生活\\study\\hadoop\\资料\\11_input\\inputtable2"));
        FileOutputFormat.setOutputPath(job,new Path("D:\\hadoopTmp\\output"));

        boolean result = job.waitForCompletion(true);
        System.exit(result?1:0);
    }
}
